#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Description:
import constants
from modules.operationBase import OperationBase
from utils.logger import Logger

log = Logger()


class QAction(OperationBase):
    def __init__(self, parse_args):
        super().__init__(parse_args)

    def action_create_qdfs_no_failgroup(self, disk_path):
        log.info("start create qdfs no failgroup")
        cmd = constants.QDFS_CREATE + disk_path
        result = self.ssh.exec_cmd(cmd)
        log.success(f"create qdfs success, result is \n {result}")

    def action_mount_qdfs(self, disk_path):
        cmd = constants.QDFS_MOUNT.format(disk_path, self.point)
        self.ssh.exec_cmd(cmd)
        log.success(f"mount qdfs success")

    def action_dev_add_qdfs(self, disk_path):
        cmd = constants.QDFS_DEV_ADD.format(self.point, disk_path)
        self.ssh.exec_cmd(cmd)
        log.success(f"qdfs add {disk_path} is success")

    def action_dev_remove_qdfs(self, disk_path):
        cmd = constants.QDFS_DEV_REMOVE.format(disk_path, self.point)
        self.ssh.exec_cmd(cmd)
        log.success(f"qdfs remove {disk_path} is success")

    def action_dev_online_qdfs(self, disk_path):
        cmd = constants.QDFS_DEV_ONLINE.format(disk_path)
        self.ssh.exec_cmd(cmd)
        log.success(f"qdfs online {disk_path} is success")

    def action_dev_offline_qdfs(self, disk_path):
        cmd = constants.QDFS_DEV_OFFLINE.format(disk_path)
        self.ssh.exec_cmd(cmd)
        log.success(f"qdfs offline {disk_path} is success")

    def action_data_rereplicate_qdfs(self):
        cmd = constants.QDFS_DATA_REREPLICATE.format(self.point)
        self.ssh.exec_cmd(cmd)
        log.success(f"qdfs rereplicate {self.point} is success")

    def action_chown(self):
        self.ssh.exec_cmd(command=constants.SYSTEM_CHOWN.format(self.point))

    def action_chmod(self):
        self.ssh.exec_cmd(command=constants.SYSTEM_CHMOD.format(self.point))

    def action_rm_rf(self):
        self.ssh.exec_cmd(command=constants.SYSTEM_RM_RF.format(self.point))

    def action_umount_qdfs(self):
        self.ssh.exec_cmd(command=constants.SYSTEM_UMOUNT.format(self.point))

